package com.acc.store.contorller;

import com.acc.store.common.Result;
import com.acc.store.service.OrderService;
import com.acc.store.vo.CountVo;
import com.acc.store.vo.OrderVo;
import com.acc.store.vo.UserOrderVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RequestMapping("/order")
@RestController
@Slf4j
@Tag(name = "订单操作")
public class OrderContorller {
    @Autowired
    OrderService orderService;
    @Operation(summary = "月销量统计")
    @GetMapping("/line")
    public Result getLine(){
        List<Map<String, BigDecimal>> list=orderService.getLine();
        return Result.success(list);
    }
    @Operation(summary = "员工销量统计")
    @GetMapping("/getdata")
    public Result getData() {
        List<UserOrderVo> list=orderService.getData();
        return Result.success(list);
    }

    @Operation(summary = "基本统计数据")
    @GetMapping("/count")
    public Result count() {
        List<CountVo> list = orderService.counts();
        return Result.success(list);
    }

    @PutMapping("/submit/{orderId}")
    @Operation(summary = "提交订单")
    public Result submit(@PathVariable Long orderId) {
        orderService.submit(orderId);
        return Result.success(null);
    }

    @PutMapping("/clear")
    @Operation(summary = "清理未提交的订单")
    public Result clear() {
        orderService.clear();

        return Result.success("");
    }

    @GetMapping("/get/{orderid}")
    @Operation(summary = "订单详情")
    public Result get(@PathVariable Long orderid) {

        OrderVo byId = orderService.total(orderid);
        return Result.success(byId);
    }

    @PutMapping("/create/{userId}")
    @Operation(summary = "根据店员Id创建订单")
    public Result create(@PathVariable Long userId) {
        Long orderId = orderService.create(userId);
        return Result.success(orderId.toString());
    }

    @GetMapping("/list")
    @Operation(summary = "订单分页")
    public Result page(@RequestParam Map<String, Object> params) {
        IPage page = orderService.getPage(params);
        return Result.success(page);
    }
}
